package br.uece.laconi.tac.strategy;

import se.sics.tac.aw.Bid;
import se.sics.tac.aw.TACAgent;
import br.uece.laconi.tac.Agent;

public class FlightStrategy extends AgentStrategy {

	protected FlightKnowledge know = null;
	
	public FlightStrategy(Agent agent) {
		super(agent);
		know = new FlightKnowledge();
	}

	@Override
	public void init() {
		// Trecho de DummyAgent.calculateAllocation()
		int auction, inFlight, outFlight;
		
		for (int i = 0; i < 8; i++) {			
			inFlight = sensor.getClientPreference(i, TACAgent.ARRIVAL);
			outFlight = sensor.getClientPreference(i, TACAgent.DEPARTURE);
			
			auction = TACAgent.getAuctionFor(TACAgent.CAT_FLIGHT, TACAgent.TYPE_INFLIGHT, inFlight);
			effector.setAllocation(auction, sensor.getAllocation(auction) + 1);
			
			auction = TACAgent.getAuctionFor(TACAgent.CAT_FLIGHT, TACAgent.TYPE_OUTFLIGHT, outFlight);
			effector.setAllocation(auction, sensor.getAllocation(auction) + 1);			
		}
		
		execute();
	}

	@Override
	public void execute() {
		// Trecho de DummyAgent.sendBids()
		for (int i = 0, n = TACAgent.getAuctionNo(); i < n; i++) {
			int alloc = sensor.getAllocation(i) - sensor.getOwn(i);
			if (TACAgent.getAuctionCategory(i) == TACAgent.CAT_FLIGHT && alloc > 0) {
				Bid bid = new Bid(i);
				bid.addBidPoint(alloc, 1000);			
				effector.submitBid(bid);
			}
		}
	}
}
